import 'dart:async';
import 'dart:io';
import 'package:acaleph/model/base_model.dart';
import 'package:acaleph/model/test_list2_model.dart';
import 'package:acaleph/mvp/repository/test_list_repository.dart';
import 'package:acaleph/utils/http_util.dart';
import 'package:dio/dio.dart';

class TestListRepositoryImpl implements TestListRepository {
  @override
  Future<BaseModel<UserInfo>> loadList( String id){
    return _getThemes();
  }
}

Future<BaseModel<UserInfo>> _getThemes() async {
  int code;

  String errorMsg;

  BaseModel<UserInfo> model;

  UserInfo userInfo;



  try {
    Dio dio = new Dio();
    Response response = await dio.get("https://dsn.apizza.net/mock/d9ece8d859722233416fa78ba498d717/user");
    print(response.data);
    code = response.statusCode;
    print(response.statusCode);

    if (response.statusCode == HttpStatus.OK||response.statusCode==200) {
      userInfo=UserInfo.fromJson(response.data);
      print('_______________________________________');
      print(userInfo);
    } else {
      errorMsg = '服务器异常';
    }
  } catch (exception) {
    errorMsg = '您的网络似乎出了什么问题';
  } finally {
    model = new BaseModel(code: code, errorMsg: errorMsg, data: userInfo);
  }

  return model;
}
